package com.liu.stockmarket.model

import java.io.Serializable

/**
 * 股票、基金
 */
data class Stock(
    /**
     * @see com.liu.stockmarket.const.TypeAlias
     */
    val Classify: String,
    /**
     * 编号
     */
    val Code: String,
    val ID: String,
    val IsExactMatch: String,
    val JYS: String,
    val JYS4App: String,
    val MarketType: String,
    val MktNum: Int,
    val MktNum4App: String,
    /**
     * 名称
     */
    val Name: String,
    val PinYin: String,
    val SecurityType: String,
    val SecurityTypeName: String


) {
    enum class StockType(val text: String) : Serializable {
        /**
         * 股票
         */
        STOCK("股票"),

        /**
         * 可转债
         */
        BOND("转债"),

        /**
         * 基金
         */
        FUND("基金"),

        ALL("总计"),


        OTHER("其他");

        companion object {
            fun securityTypeToStockType(securityType: String): StockType {
                return when (securityType) {
                    "1", "2", "7", "19" -> {
                        STOCK
                    }
                    "17" -> {
                        FUND
                    }
                    "21" -> {
                        BOND
                    }
                    else -> {
                        OTHER
                    }
                }
            }
        }

    }

    /**
     * 交易渠道
     */
    enum class TransactionExchange(private val code: Int) : Serializable {
        /**
         * 沪A
         */
        SH(1),

        /**
         * 深A
         */
        SZ(0),


        USA(106),
        HK(116),

        /**
         * 其他
         */
        OTHER(-1);

        fun getCode() = this.code

        companion object {
            fun marketTypeToTransactionExchange(marketType: String): TransactionExchange {
                return when (marketType) {
                    "1" -> {
                        SH
                    }
                    "2" -> {
                        SZ
                    }
                    "5" -> {
                        HK
                    }
                    "7" -> {
                        USA
                    }
                    else -> {
                        OTHER
                    }
                }
            }
        }
    }
}